const Koa = require('koa')

// 实例化应用
const app = new Koa()

async function errorHandler(ctx, next) {
    try {
        await next()
    } catch (e) {
        ctx.status = e.status || 500
        ctx.body = `System Error: ${e.message}`
    }
}

app.use(errorHandler)

app.use(ctx => {
    ctx.throw(403, 'Forbidden')
})

app.listen(8899, () => {
    console.log('listen on 8899');
})